import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/extension/lx_colors.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';
import 'package:lx_widgets_library/model/base_model.dart';

class InformationDetailView extends StatelessWidget {
  // 标题
  final String title;

  // item列表
  final RxList<LxBaseModel> itemList;

  // 扩展的组件
  final Widget? extendedWidget;

  InformationDetailView({
    required this.title,
    required this.itemList,
    this.extendedWidget,
  });

  @override
  Widget build(BuildContext context) {
    double cellH = 38;
    return Obx(
      () => Padding(
        padding: EdgeInsets.only(
          left: CONTENT_MARGIN,
          right: CONTENT_MARGIN,
          top: CONTENT_MARGIN,
          bottom: CONTENT_MARGIN / 2,
        ),
        child: ClipRRect(
          borderRadius: const BorderRadius.all(Radius.circular(8)),
          child: Container(
            padding: EdgeInsets.all(CONTENT_MARGIN),
            color: LxColors.borderBackgroud,
            width: double.infinity,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(
                  height: cellH - CONTENT_MARGIN / 2,
                  child: LxText(
                    title,
                    color: Colors.white.withOpacity(0.6),
                    fontWeightEnum: LxFontWeightEnum.bodyMedium,
                  ),
                ),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: itemList.asMap().keys.map((index) {
                    return Column(
                      children: [
                        Visibility(
                          visible: itemList[index].val.value.isNotEmpty,
                          child: Container(
                            color: Colors.transparent,
                            height: cellH,
                            child: Center(
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: [
                                  LxText(
                                    itemList[index].bigTitle.value,
                                    color: Colors.white,
                                    fontWeightEnum: LxFontWeightEnum.bodyMedium,
                                  ),
                                  LxText(
                                    itemList[index].val.value,
                                    color: Colors.white,
                                    fontWeightEnum: LxFontWeightEnum.bodyMedium,
                                  )
                                ],
                              ),
                            ),
                          ),
                        ),
                        Visibility(
                          visible: index != itemList.length - 1 ||
                              extendedWidget != null,
                          child: Divider(
                            height: 1,
                            color: LxColors.cellLine,
                          ),
                        ),
                      ],
                    );
                  }).toList(),
                ),
                extendedWidget == null ? Container() : extendedWidget!,
              ],
            ),
          ),
        ),
      ),
    );
  }
}
